package cn.daniellee;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

public class Config {

	private static Properties prop = new Properties();
	
	static{
		try {
			InputStream is = new FileInputStream(new File("config.properties"));
			prop.load(is);
			is.close();
		} catch (Throwable ignored) { }
	}
	
	public static String getProp(String key){
		return prop.getProperty(key);
	}

	public static String getProp(String key, String defaultValue){
		String value = prop.getProperty(key);
		return value == null ? defaultValue : value;
	}

	public static int getInt(String key,int defaultVal){
		try{
			return Integer.parseInt(prop.getProperty(key));
		}catch(NumberFormatException e){
			return defaultVal;
		}	
	}

	public static boolean getBoolean(String key, boolean defaultVal){
		try{
			return Boolean.parseBoolean(prop.getProperty(key));
		}catch(NumberFormatException e){
			return defaultVal;
		}
	}
}
